package com.hiray.demos.ui_architect.litho.list

import android.graphics.Color
import android.widget.Toast
import com.facebook.litho.ClickEvent
import com.facebook.litho.Column
import com.facebook.litho.Component
import com.facebook.litho.ComponentContext
import com.facebook.litho.annotations.LayoutSpec
import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.OnEvent
import com.facebook.litho.annotations.Prop
import com.facebook.litho.widget.Text
import com.facebook.yoga.YogaEdge

@LayoutSpec(value = "ListItem")
object ListItemSpec {


    @OnCreateLayout
    fun onCreateLayout(c: ComponentContext,@Prop title:String,@Prop subTitle:String ): Component {
        return Column.create(c)
                .paddingDip(YogaEdge.ALL, 16f)
                .backgroundColor(Color.WHITE)
                .child(
                        Text.create(c)
                                .text(title)
                                .textSizeSp(40f))
                .child(
                        Text.create(c)
                                .text(subTitle)
                                .textSizeSp(20f))
                .clickHandler(ListItem.onItemClick(c))
                .build()
    }

    @OnEvent(value = ClickEvent::class)
    fun onItemClick(c: ComponentContext,@Prop title:String) {
        Toast.makeText(c.androidContext, title, Toast.LENGTH_SHORT).show()
    }

}